home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example5.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  6KB  |  180 lines

  1. /* Example5                                                */
  2. /* This program explains how to use the IDCMP flag RAWKEY. */
  3.  
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7.  
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13.  
  14. /* Declare a pointer to a Window structure: */ 
  15. struct Window *my_window;
  16.  
  17. /* Declare and initialize your NewWindow structure: */
  18. struct NewWindow my_new_window=
  19. {
  20.   50,             /* LeftEdge    x position of the window. */
  21.   25,             /* TopEdge     y positio of the window. */
  22.   320,            /* Width       320 pixels wide. */
  23.   100,            /* Height      100 lines high. */
  24.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  25.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  26.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  27.                   /*             selects the Close window gad.           */
  28.  
  29.   RAWKEY,         /*             We will also recieve a message whenever */
  30.                   /*             the user presses/releases a key.        */
  31.  
  32.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  33.   WINDOWCLOSE|    /*             Close Gadget. */
  34.   WINDOWDRAG|     /*             Drag gadget. */
  35.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  36.   WINDOWSIZING|   /*             Sizing Gadget. */
  37.   ACTIVATE,       /*             The window should be Active when opened. */
  38.   NULL,           /* FirstGadget No gadgets connected to this window. */
  39.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  40.   "PRESS MY KEYS",/* Title       Title of the window. */
  41.   NULL,           /* Screen      Connected to the Workbench Screen. */
  42.   NULL,           /* BitMap      No Custom BitMap. */
  43.   100,            /* MinWidth    We will not allow the window to become */
  44.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  45.   400,            /* MaxWidth    than 400 x 200. */
  46.   200,            /* MaxHeight */
  47.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  48. };
  49.  
  50.  
  51.  
  52. /**************************************************************************/
  53. /* Extra information:                                                     */
  54. /* Whenever the user presses/releases a key will we recieve a message.    */
  55. /* The Code part of the message contains the raw (untranslated) keykodes. */
  56. /* (See Appendix * for more information about raw keykodes.) The          */
  57. /* Qualifier field of the message tells us if any qualifier (SHIFT/CTRL   */
  58. /* etc) was also pressed. (See Appendix * for more information about      */
  59. /* qualifiers.                                                            */
  60. /**************************************************************************/
  61.  
  62.  
  63.  
  64. main()
  65. {
  66.   /* Boolean variable used for the while loop: */
  67.   BOOL close_me;
  68.  
  69.   ULONG class;      /* IDCMP flag. */
  70.   USHORT code;      /* Code. */
  71.   USHORT qualifier; /* Qualifier. */
  72.  
  73.   /* Pointer to an IntuiMessage structure: */
  74.   struct IntuiMessage *my_message;
  75.  
  76.  
  77.  
  78.   /* Before we can use Intuition we need to open the Intuition Library: */
  79.   IntuitionBase = (struct IntuitionBase *)
  80.     OpenLibrary( "intuition.library", 0 );
  81.   
  82.   if( IntuitionBase == NULL )
  83.     exit(); /* Could NOT open the Intuition Library! */
  84.  
  85.  
  86.  
  87.   /* We will now try to open the window: */
  88.   my_window = (struct Window *) OpenWindow( &my_new_window );
  89.   
  90.   /* Have we opened the window succesfully? */
  91.   if(my_window == NULL)
  92.   {
  93.     /* Could NOT open the Window! */
  94.     
  95.     /* Close the Intuition Library since we have opened it: */
  96.     CloseLibrary( IntuitionBase );
  97.  
  98.     exit();  
  99.   }
  100.  
  101.  
  102.  
  103.   /* We have opened the window, and everything seems to be OK. */
  104.  
  105.   printf("Press some keys!\n\n");
  106.  
  107.  
  108.  
  109.   close_me = FALSE;
  110.  
  111.   /* Stay in the while loop until the user has selected the Close window */
  112.   /* gadget: */
  113.   while( close_me == FALSE )
  114.   {
  115.     /* Wait until we have recieved a message: */
  116.     Wait( 1 << my_window->UserPort->mp_SigBit );
  117.  
  118.  
  119.     /* As long as we can collect messages successfully we stay in the */
  120.     /* while-loop: */
  121.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  122.     {
  123.       /* After we have successfully collected the message we can read */
  124.       /* it, and save any important values which we maybe want to check */
  125.       /* later: */
  126.       class = my_message->Class;         /* IDCMP flag. */
  127.       code = my_message->Code;           /* Code. */
  128.       qualifier = my_message->Qualifier; /* Qualifier. */
  129.  
  130.  
  131.       /* After we have read it we reply as fast as possible: */
  132.       /* REMEMBER! Do never try to read a message after you have replied! */
  133.       /* (Some other process has maybe changed it.) */
  134.       ReplyMsg( my_message );
  135.  
  136.  
  137.       /* Check which IDCMP flag was sent: */
  138.       switch( class )
  139.       {
  140.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  141.                close_me=TRUE;
  142.                break;
  143.  
  144.         case RAWKEY:         /* The user pressed/released a key! */
  145.                /* Print out the raw keycode (both as decimal and hex.): */
  146.                printf("Raw keycode: %6d(d) %6x(h)\n", code, code );
  147.                
  148.                /* Print out the qualifier (both as decimal and hex.): */
  149.                printf("Qualifier:   %6d(d) %6x(h)\n", qualifier, qualifier);
  150.                
  151.                /* This shows how you can check if a SHIFT or CTRL */
  152.                /* qualifier key was also pressed:                 */
  153.                if( qualifier &= IEQUALIFIER_LSHIFT )
  154.                  printf("Left SHIFT button pressed\n");
  155.  
  156.                if( qualifier &= IEQUALIFIER_RSHIFT )
  157.                  printf("Right SHIFT button pressed\n");
  158.                
  159.                if( qualifier &= IEQUALIFIER_CONTROL )
  160.                  printf("CTRL button pressed\n");
  161.  
  162.                printf("\n");
  163.                break;
  164.       }
  165.     }
  166.   }
  167.  
  168.  
  169.  
  170.   /* Close the window: */
  171.   CloseWindow( my_window );
  172.  
  173.  
  174.  
  175.   /* Close the Intuition Library: */
  176.   CloseLibrary( IntuitionBase );
  177.   
  178.   /* THE END */
  179. }
  180.